<?php
/**
 * 
 * @App	
 * @Group 
 * @Action HashTrait
 * @author lilei
 * @date 2018年5月25日
 *
 */
namespace app\common\redis\traits;

trait HashTrait{
	/**
	 * Redis 操作句柄
	 * @var CacheRedis|Redis
	 */
	public $redis_handle ;
	
	/**
	 * 获取Hash所有的key
	 */
	public function HashAllFields($key='') {
		$_key = $key ?: $this->key;
		$res =  $this->redis_handle->hKeys($_key);
		return $res;
	}
	
	/**
	 * 获取Hash所有的字段和值
	 */
	public function HashGetAll($key='') {
		$_key = $key ?: $this->key;
		$res = $this->redis_handle->hGetAll($_key);
		return $res;
	}
	
	/**
	 * 获取Hash某一字段的值
	 */
	public function HashGetByField($field, $key='') {
		$_key = $key ?: $this->key;
		$res = $this->redis_handle->hGet($_key, $field);
		return $res;
	}

    /**
     * 设置Hash某一字段的值
     */
    public function HashSetField($field, $value, $key='') {
        $_key = $key ?: $this->key;
        $res = $this->redis_handle->hSet( $_key, $field, $value );
        return $res;
    }

    /**
     * 设置Hash某一字段的值
     */
    public function HashSetAll($value, $key='') {
        $_key = $key ?: $this->key;
        $res = $this->redis_handle->hMset( $_key, $value );
        return $res;
    }


    /**
     * 批量获取
     */
    public function HashMGet($value, $key='') {
        $_key = $key ?: $this->key;
        $res = $this->redis_handle->hMGet( $_key, $value );
        return $res;
    }


}
?>